<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="UTF-8" />
    <title>Datetime Button - Custom Buttons</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
    <link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
    <link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
    <script src="../../../../../scripts/testing/scripts.js"></script>
    <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
  </head>
  <body>
    <ion-app>
      <ion-header>
        <ion-toolbar>
          <ion-title>Datetime Button - Custom Buttons</ion-title>
        </ion-toolbar>
      </ion-header>
      <ion-content>
        <ion-item>
          <ion-input aria-label="input" value="March 15, 2022 at 12:43 AM"></ion-input>
          <ion-datetime-button slot="end" id="default-button" datetime="default-datetime">
            <ion-icon color="primary" id="custom-date-button" slot="date-target" name="calendar"></ion-icon>
            <ion-icon color="primary" id="custom-time-button" slot="time-target" name="time"></ion-icon>
          </ion-datetime-button>
        </ion-item>

        <ion-popover arrow="false">
          <ion-datetime
            locale="en-US"
            presentation="date-time"
            id="default-datetime"
            value="2022-03-15T00:43:00"
          ></ion-datetime>
        </ion-popover>
      </ion-content>

      <script>
        const datetime = document.querySelector('ion-datetime');
        const input = document.querySelector('ion-input');
        datetime.addEventListener('ionChange', (ev) => {
          input.value = new Intl.DateTimeFormat('en-US', { dateStyle: 'long', timeStyle: 'short' }).format(
            new Date(ev.detail.value)
          );
        });
      </script>
    </ion-app>
  </body>
</html>
